package com.matrix.draft.rabbitmqspringboot.rabbitmq.consumer;

import cn.hutool.core.lang.Console;
import com.matrix.draft.rabbitmqspringboot.config.AdvanceRabbitMQConfig;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 报警队列和数据队列的消费者
 */
@Component
public class QueueWarnAndBackupConsumer {

    @RabbitListener(queues = {AdvanceRabbitMQConfig.queueWarn,AdvanceRabbitMQConfig.queueBackup})
    void receiveMessage(Message msg){
        String queueName = msg.getMessageProperties().getConsumerQueue();
        switch (queueName){
            case AdvanceRabbitMQConfig.queueBackup:
                Console.log("Receiving {}'s message: {} , DataBackup done",queueName,new String(msg.getBody()));
                break;
            case AdvanceRabbitMQConfig.queueWarn:
                Console.log("Receiving {}'s message: {} , Warn done",queueName,new String(msg.getBody()));
                break;
        }
    }

}
